package calorie.com.calorie.contact;

import android.content.Context;


import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.Md5Utils;
import com.lxh.baselibray.util.SPUtils;
import com.lxh.baselibray.util.ToastUtils;

import calorie.com.calorie.api.ApiService;
import calorie.com.calorie.constant.Constant;
import calorie.com.calorie.request.BuyAccelerateRequest;
import calorie.com.calorie.response.AccelerateResponce;
import calorie.com.calorie.response.BuyAccelerateResponce;
import calorie.com.calorie.response.ResultDTO;
import retrofit2.Call;
import retrofit2.Response;

public class AccelerateContact {
    public static class AcceleratePresent extends BasePresent<IAccelerateView> {
        public void buyAccelerate(Context context, String dealPwd) {
            ApiService service = ServiceGenerator.createService(ApiService.class);
            int userId = SPUtils.getInt(Constant.USER_ID, -1, context);
            BuyAccelerateRequest request = new BuyAccelerateRequest(userId, Md5Utils.stringToMD5(dealPwd));
            service.buyAccelerate(request).enqueue(new NetCallBack<BuyAccelerateResponce>() {
                @Override
                public void onSuccess(Call<BuyAccelerateResponce> call, Response<BuyAccelerateResponce> response) {
                    if (getView() != null) {
                        getView().getBuyAccelerateData(response);
                    }
                }

                @Override
                public void onFailed() {
                    //ToastUtils.showLongToast(context, "网络请求异常");
                }
            });
        }

        public void getPrice() {
            ApiService service = ServiceGenerator.createService(ApiService.class);


            service.getAcceleratePrice().enqueue(new NetCallBack<ResultDTO>() {
                @Override
                public void onSuccess(Call<ResultDTO> call, Response<ResultDTO> response) {
                    if (getView() != null) {
                        getView().getPriceResult(response);
                    }
                }

                @Override
                public void onFailed() {

                }
            });
        }

        public void queryAccelerateList(Context context) {
            ApiService service = ServiceGenerator.createService(ApiService.class);
            int userId = SPUtils.getInt(Constant.USER_ID, -1, context);
            service.accelerateList(userId).enqueue(new NetCallBack<AccelerateResponce>() {
                @Override
                public void onSuccess(Call<AccelerateResponce> call, Response<AccelerateResponce> response) {
                    if (getView() != null) {
                        getView().getAccelerateList(response);
                    }
                }

                @Override
                public void onFailed() {
                   // ToastUtils.showLongToast(context, "网络请求异常");
                }
            });
        }
    }

    public interface IAccelerateView extends IBaseView {
        void getBuyAccelerateData(Response<BuyAccelerateResponce> response);

        void getAccelerateList(Response<AccelerateResponce> response);

        public void getPriceResult(Response<ResultDTO> response);
    }
}
